home *** CD-ROM | disk | FTP | other *** search
/ Java Interactive Reference Guide / Java Interactive Reference Guide.iso / autorun / source.dir / 00010_15.txt < prev    next >
Encoding:
Text File  |  1980-01-11  |  3.2 KB  |  103 lines

  1. /*
  2.  * @(#)AniArea.java    1.4 95/10/13  
  3.  *
  4.  * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
  8.  * without fee is hereby granted. 
  9.  * Please refer to the file http://java.sun.com/copy_trademarks.html
  10.  * for further important copyright and trademark information and to
  11.  * http://java.sun.com/licensing.html for further important licensing
  12.  * information for the Java (tm) Technology.
  13.  * 
  14.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  15.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  18.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  19.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  20.  * 
  21.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  22.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  23.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  24.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  25.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  26.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  27.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  28.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  29.  * HIGH RISK ACTIVITIES.
  30.  */
  31.  
  32. import java.awt.Graphics;
  33. import java.util.StringTokenizer;
  34. import java.awt.Image;
  35. import java.net.URL;
  36. import java.net.MalformedURLException;
  37.  
  38. /**
  39.  * This ImageArea provides for a button that animates when the mouse is
  40.  * over it. The animation is specifed as a base image that contains all
  41.  * of the animation frames and then a series of X,Y coordinate pairs that
  42.  * define the top left corner of each new frame.
  43.  *
  44.  * @author    Chuck McManis
  45.  * @version    1.4, 10/13/95
  46.  */
  47. class AniArea extends ImageMapArea {
  48.  
  49.     Image sourceImage;
  50.     int     nFrames;
  51.     int  coords[];
  52.     int     currentFrame = 0;
  53.  
  54.     public void handleArg(String s) {
  55.     StringTokenizer st = new StringTokenizer(s, ", ");
  56.     int    i;
  57.         String imgName;
  58.  
  59.     imgName = st.nextToken();
  60.     try {
  61.     sourceImage = parent.getImage(
  62.             new URL(parent.getDocumentBase(), imgName));
  63.     } catch (MalformedURLException e) {}
  64.  
  65.     nFrames = 0;
  66.     coords = new int[40];
  67.  
  68.     while (st.hasMoreTokens()) {
  69.         coords[nFrames*2]     = Integer.parseInt(st.nextToken());
  70.         coords[(nFrames*2)+1] = Integer.parseInt(st.nextToken());
  71.         nFrames++;
  72.         if (nFrames > 19)
  73.         break;
  74.     }
  75.     }
  76.  
  77.     public boolean animate() {
  78.     if (entered) {
  79.         repaint();
  80.     }
  81.     return entered;
  82.     }
  83.  
  84.     public boolean enter() {
  85.     currentFrame = 0;
  86.     parent.startAnimation();
  87.     return false;
  88.     }
  89.  
  90.     public void highlight(Graphics g) {
  91.     if (entered) {
  92.         drawImage(g, sourceImage, 
  93.               X-coords[currentFrame*2], Y-coords[(currentFrame*2)+1],
  94.               X, Y, W, H);
  95.         currentFrame++;
  96.         if (currentFrame >= nFrames)
  97.         currentFrame = 0;
  98.     }
  99.     }
  100. }
  101.  
  102.  
  103.